#include<iostream>
#include<unordered_map>
using namespace std;

unordered_map<long long, int> a;
long long ans;
int main()
{
	int n, m;
	cin >> n >> m;
	long long x;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		a[i * x]++;
	}
	for (int i = 1; i <= m; i++) {
		cin >> x;
		if (x)ans += a[i * x];
	}
	cout << ans << endl;
	return 0;
}